package demo1;

class Solution2 {
    public boolean isPalindrome(ListNode head) {
       ListNode slow  = head ;
       ListNode fast = head ;
       while(fast!=null&&fast.next!=null){
           fast = fast.next .next ;
           slow = slow .next ;
       }
       ListNode cur = slow.next ;
       while(cur!=null){
         ListNode curNext= cur.next ;
         cur.next = slow ;
         slow = cur ;
          cur = curNext ;
       }
     fast = head ;
       while(fast!=slow){
         if(fast.val!=slow.val){
             return false ;
         }
         if(fast.next == slow){
             return true ;
         }       
           fast = fast.next ;
            slow = slow.next ;
       }

       return true ;

    }
}